package org.neptune.service.redis;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lwl
 * @date 2019/8/5 13:56
 */
@Configuration
public class RedisConfig {

	@Autowired
	private RedisProperties redisProperties;

	/**
	 * 单机版配置
	 *
	 * @return
	 */
	@Bean(name = "redissonSingle")
	public RedissonClient redissonClient() {

		Config config = new Config();
		config.useSingleServer()
				.setAddress(redisProperties.getSingleNode())
				.setConnectionPoolSize(redisProperties.getMaxIdle())
				.setTimeout(redisProperties.getMaxWait()).setDatabase(redisProperties.getDatabase())
				.setConnectionMinimumIdleSize(redisProperties.getMinIdle())
				.setPassword(redisProperties.getPassword());
		return Redisson.create(config);
	}
}
